/*   1:    */ package com.htxx.security.cipher;
/*   2:    */ 
/*   3:    */ public class CryptoUtils
/*   4:    */ {
/*   5:    */   public static void zeroBlock(byte[] block, int off, int len)
/*   6:    */   {
/*   7: 10 */     for (int i = off; i < off + len; i++) {
/*   8: 11 */       block[i] = 0;
/*   9:    */     }
/*  10:    */   }
/*  11:    */   
/*  12:    */   public static void zeroBlock(byte[] block)
/*  13:    */   {
/*  14: 16 */     zeroBlock(block, 0, block.length);
/*  15:    */   }
/*  16:    */   
/*  17:    */   public static void randomBlock(byte[] block, int off, int len)
/*  18:    */   {
/*  19: 21 */     for (int i = off; i < off + len; i++) {
/*  20: 22 */       block[i] = ((byte)(int)(Math.random() * 256.0D));
/*  21:    */     }
/*  22:    */   }
/*  23:    */   
/*  24:    */   public static void randomBlock(byte[] block)
/*  25:    */   {
/*  26: 27 */     randomBlock(block, 0, block.length);
/*  27:    */   }
/*  28:    */   
/*  29:    */   public static void xorBlock(byte[] a, int aOff, byte[] b, int bOff, byte[] dst, int dstOff, int len)
/*  30:    */   {
/*  31: 32 */     for (int i = 0; i < len; i++) {
/*  32: 33 */       dst[(dstOff + i)] = ((byte)(a[(aOff + i)] ^ b[(bOff + i)]));
/*  33:    */     }
/*  34:    */   }
/*  35:    */   
/*  36:    */   public static void xorBlock(byte[] a, byte[] b, byte[] dst)
/*  37:    */   {
/*  38: 38 */     xorBlock(a, 0, b, 0, dst, 0, a.length);
/*  39:    */   }
/*  40:    */   
/*  41:    */   public static void copyBlock(byte[] src, int srcOff, byte[] dst, int dstOff, int len)
/*  42:    */   {
/*  43: 43 */     for (int i = 0; i < len; i++) {
/*  44: 44 */       dst[(dstOff + i)] = src[(srcOff + i)];
/*  45:    */     }
/*  46:    */   }
/*  47:    */   
/*  48:    */   public static void copyBlock(byte[] src, byte[] dst)
/*  49:    */   {
/*  50: 49 */     copyBlock(src, 0, dst, 0, src.length);
/*  51:    */   }
/*  52:    */   
/*  53:    */   public static boolean equalsBlock(byte[] a, int aOff, byte[] b, int bOff, int len)
/*  54:    */   {
/*  55: 54 */     for (int i = 0; i < len; i++) {
/*  56: 55 */       if (a[(aOff + i)] != b[(bOff + i)]) {
/*  57: 56 */         return false;
/*  58:    */       }
/*  59:    */     }
/*  60: 58 */     return true;
/*  61:    */   }
/*  62:    */   
/*  63:    */   public static boolean equalsBlock(byte[] a, byte[] b)
/*  64:    */   {
/*  65: 63 */     return equalsBlock(a, 0, b, 0, a.length);
/*  66:    */   }
/*  67:    */   
/*  68:    */   public static void fillBlock(byte[] block, int blockOff, byte b, int len)
/*  69:    */   {
/*  70: 68 */     for (int i = blockOff; i < blockOff + len; i++) {
/*  71: 69 */       block[i] = b;
/*  72:    */     }
/*  73:    */   }
/*  74:    */   
/*  75:    */   public static void fillBlock(byte[] block, byte b)
/*  76:    */   {
/*  77: 74 */     fillBlock(block, 0, b, block.length);
/*  78:    */   }
/*  79:    */   
/*  80:    */   public static void squashBytesToInts(byte[] inBytes, int inOff, int[] outInts, int outOff, int intLen)
/*  81:    */   {
/*  82: 79 */     for (int i = 0; i < intLen; i++) {
/*  83: 80 */       outInts[(outOff + i)] = 
/*  84:    */       
/*  85:    */ 
/*  86: 83 */         ((inBytes[(inOff + i * 4)] & 0xFF) << 24 | (inBytes[(inOff + i * 4 + 1)] & 0xFF) << 16 | (inBytes[(inOff + i * 4 + 2)] & 0xFF) << 8 | inBytes[(inOff + i * 4 + 3)] & 0xFF);
/*  87:    */     }
/*  88:    */   }
/*  89:    */   
/*  90:    */   public static void spreadIntsToBytes(int[] inInts, int inOff, byte[] outBytes, int outOff, int intLen)
/*  91:    */   {
/*  92: 88 */     for (int i = 0; i < intLen; i++)
/*  93:    */     {
/*  94: 90 */       outBytes[(outOff + i * 4)] = ((byte)(inInts[(inOff + i)] >>> 24 & 0xFF));
/*  95: 91 */       outBytes[(outOff + i * 4 + 1)] = ((byte)(inInts[(inOff + i)] >>> 16 & 0xFF));
/*  96: 92 */       outBytes[(outOff + i * 4 + 2)] = ((byte)(inInts[(inOff + i)] >>> 8 & 0xFF));
/*  97: 93 */       outBytes[(outOff + i * 4 + 3)] = ((byte)(inInts[(inOff + i)] & 0xFF));
/*  98:    */     }
/*  99:    */   }
/* 100:    */   
/* 101:    */   public static void squashBytesToIntsLittle(byte[] inBytes, int inOff, int[] outInts, int outOff, int intLen)
/* 102:    */   {
/* 103: 99 */     for (int i = 0; i < intLen; i++) {
/* 104:100 */       outInts[(outOff + i)] = 
/* 105:    */       
/* 106:    */ 
/* 107:103 */         (inBytes[(inOff + i * 4)] & 0xFF | (inBytes[(inOff + i * 4 + 1)] & 0xFF) << 8 | (inBytes[(inOff + i * 4 + 2)] & 0xFF) << 16 | (inBytes[(inOff + i * 4 + 3)] & 0xFF) << 24);
/* 108:    */     }
/* 109:    */   }
/* 110:    */   
/* 111:    */   public static void spreadIntsToBytesLittle(int[] inInts, int inOff, byte[] outBytes, int outOff, int intLen)
/* 112:    */   {
/* 113:108 */     for (int i = 0; i < intLen; i++)
/* 114:    */     {
/* 115:110 */       outBytes[(outOff + i * 4)] = ((byte)(inInts[(inOff + i)] & 0xFF));
/* 116:111 */       outBytes[(outOff + i * 4 + 1)] = ((byte)(inInts[(inOff + i)] >>> 8 & 0xFF));
/* 117:112 */       outBytes[(outOff + i * 4 + 2)] = ((byte)(inInts[(inOff + i)] >>> 16 & 0xFF));
/* 118:113 */       outBytes[(outOff + i * 4 + 3)] = ((byte)(inInts[(inOff + i)] >>> 24 & 0xFF));
/* 119:    */     }
/* 120:    */   }
/* 121:    */   
/* 122:    */   public static void squashBytesToShorts(byte[] inBytes, int inOff, int[] outShorts, int outOff, int shortLen)
/* 123:    */   {
/* 124:119 */     for (int i = 0; i < shortLen; i++) {
/* 125:120 */       outShorts[(outOff + i)] = ((inBytes[(inOff + i * 2)] & 0xFF) << 8 | inBytes[(inOff + i * 2 + 1)] & 0xFF);
/* 126:    */     }
/* 127:    */   }
/* 128:    */   
/* 129:    */   public static void spreadShortsToBytes(int[] inShorts, int inOff, byte[] outBytes, int outOff, int shortLen)
/* 130:    */   {
/* 131:125 */     for (int i = 0; i < shortLen; i++)
/* 132:    */     {
/* 133:127 */       outBytes[(outOff + i * 2)] = ((byte)(inShorts[(inOff + i)] >>> 8 & 0xFF));
/* 134:128 */       outBytes[(outOff + i * 2 + 1)] = ((byte)(inShorts[(inOff + i)] & 0xFF));
/* 135:    */     }
/* 136:    */   }
/* 137:    */   
/* 138:    */   public static void squashBytesToShortsLittle(byte[] inBytes, int inOff, int[] outShorts, int outOff, int shortLen)
/* 139:    */   {
/* 140:134 */     for (int i = 0; i < shortLen; i++) {
/* 141:135 */       outShorts[(outOff + i)] = (inBytes[(inOff + i * 2)] & 0xFF | (inBytes[(inOff + i * 2 + 1)] & 0xFF) << 8);
/* 142:    */     }
/* 143:    */   }
/* 144:    */   
/* 145:    */   public static void spreadShortsToBytesLittle(int[] inShorts, int inOff, byte[] outBytes, int outOff, int shortLen)
/* 146:    */   {
/* 147:140 */     for (int i = 0; i < shortLen; i++)
/* 148:    */     {
/* 149:142 */       outBytes[(outOff + i * 2)] = ((byte)(inShorts[(inOff + i)] & 0xFF));
/* 150:143 */       outBytes[(outOff + i * 2 + 1)] = ((byte)(inShorts[(inOff + i)] >>> 8 & 0xFF));
/* 151:    */     }
/* 152:    */   }
/* 153:    */   
/* 154:    */   public static String toStringBlock(byte[] block, int off, int len)
/* 155:    */   {
/* 156:149 */     String hexits = "0123456789abcdef";
/* 157:150 */     StringBuffer buf = new StringBuffer();
/* 158:152 */     for (int i = off; i < off + len; i++)
/* 159:    */     {
/* 160:154 */       buf.append(hexits.charAt(block[i] >>> 4 & 0xF));
/* 161:155 */       buf.append(hexits.charAt(block[i] & 0xF));
/* 162:    */     }
/* 163:157 */     return "[" + buf + "]";
/* 164:    */   }
/* 165:    */   
/* 166:    */   public static String toStringBlock(byte[] block)
/* 167:    */   {
/* 168:162 */     return toStringBlock(block, 0, block.length);
/* 169:    */   }
/* 170:    */ }


/* Location:           D:\htjs\document\wsrz\WsrzEjbInf\
 * Qualified Name:     com.htxx.security.cipher.CryptoUtils
 * JD-Core Version:    0.7.0.1
 */